//
//  HomeClassTableViewCell.m
//  ForestPack
//
//  Created by 郑洲 on 2018/7/9.
//  Copyright © 2018年 郑洲. All rights reserved.
//

#import "HomeClassTableViewCell.h"

@implementation HomeClassTableViewCell

+ (HomeClassTableViewCell *)cellWithTableView:(UITableView *)tableView andIndexPath:(NSIndexPath *)indexPath{
    static NSString *cellID = @"HomeClassTableViewCell";
    HomeClassTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:cellID];
    if (cell == nil) {
        cell = [[HomeClassTableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:cellID];
        cell.selectionStyle = UITableViewCellSelectionStyleNone;
        cell.backgroundColor = [UIColor whiteColor];
        [cell createSubView];
    }
    
    return cell;
}

- (void)createSubView {
    NSArray *nameArr = @[@"纸板订购",@"个性化定制",@"解决方案",@"纸箱订购",@"包装辅料",@"帮我下单"];
    CGFloat width = SCREEN_WIDTH / 3;
    CGFloat height = ScreenX375(159) / 2;
    for (int i = 0; i < nameArr.count; i++) {
        
//        if (i == 4) {//包装辅料
//            self.buyType = BuyType_PackageBuy;
//        }else if(i == 0){//纸板订购
//            self.buyType = BuyType_PaperBuy;
//        }else if(i == 3){
//            self.buyType = BuyType_PaperBoxBuy;
//        }else{
//            return;
//        }
        
        UIView *bgView = [[UIView alloc] initWithFrame:CGRectMake(i % 3 * width, i / 3 * height, width, height)];
        [self addSubview:bgView];
        
        UIImageView *icon = [[UIImageView alloc] initWithFrame:CGRectMake((width - ScreenX375(27)) / 2, ScreenX375(16), ScreenX375(27), ScreenX375(27))];
        icon.image = [UIImage imageNamed:nameArr[i]];
        [bgView addSubview:icon];
        
        UILabel *nameLabel = [[UILabel alloc] initWithFrame:CGRectMake(0, ScreenX375(50), width, ScreenX375(16))];
        nameLabel.text = nameArr[i];
        nameLabel.textAlignment = NSTextAlignmentCenter;
        nameLabel.font = Kfont(14);
        nameLabel.textColor = REXADECIMALCOLOR(@"#333333");
        [bgView addSubview:nameLabel];
        
        UIButton *classBtn = [[UIButton alloc] initWithFrame:CGRectMake(i % 3 * width, i / 3 * height, width, height)];
        classBtn.backgroundColor = [UIColor clearColor];
        classBtn.tag = 100 + i;
        [classBtn addTarget:self action:@selector(classClick:) forControlEvents:UIControlEventTouchUpInside];
        [self addSubview:classBtn];
        
        
    }
}

- (void)classClick:(UIButton *)btn{
    if (_indexClick) {
        _indexClick(btn.tag - 100);
    }
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}

@end
